﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using TKFA.Common;
using System.Data;
using System.Configuration;
using Newtonsoft.Json;
using Newtonsoft.Json.Converters;
using System.Data.OracleClient;
using TKFA.BLL;
namespace FixedAssets
{
    /// <summary>
    /// Summary description for fa
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class fa : System.Web.Services.WebService
    {
        private string connStr = ConfigurationManager.ConnectionStrings["OracleConnectionString"].ToString();

        [WebMethod (Description="获取当前盘点计划")]
        public string getCurrentPlan()
        {
            ConnForOracle ora = new ConnForOracle(connStr);
            ora.OpenConn();
            string sql = "select SCHECKPLANID,SCHECKPLANNAME,count(*)AS num from FA_CHECKPLAN group by SCHECKPLANID,SCHECKPLANNAME";
            DataTable tbl = ora.Select(sql, null);

           // string scheckplanname = tb1[0][0];

            string json = JsonConvert.SerializeObject(tbl, new DataTableConverter());   //datatable转换为json
            ora.CloseConn();
            return json;
        
        }



        [WebMethod(Description = "获取当前盘点计划内数据")]
        public string getCurrentPlanData(string scheckplanid)
        {
            ConnForOracle ora = new ConnForOracle(connStr);
            ora.OpenConn();
            string sql = "select * from FA_CHECKPLAN where SCHECKPLANID=:scheckplanid";
            OracleParameter pa = new OracleParameter("scheckplanid", scheckplanid);

            DataTable viewdt = ora.Select(sql, pa);
          
            string json = JsonConvert.SerializeObject(viewdt, new DataTableConverter());   //datatable转换为json
            ora.CloseConn();
            return json;
        }


        [WebMethod(Description = "设置盘点结果")]
        public void setPlanResult(string planid,string scheckplanname)
        {
            DataTable dt = (DataTable)JsonConvert.DeserializeObject<DataTable>(scheckplanname);
            TKFA.BLL.FA_CHECK check = new FA_CHECK();
            check.SetCheck(planid,dt);
            //viewdt = viewdt.DefaultView.ToTable(true, new string[] { "SCORPCODE", "SCONTENTCODE" });
           // DataRow[] drss = dt.Select("DIC_CODE = '1'");
           // string a = drss[0][2].ToString();
           // return a;
        }




    }
}
